import 'package:boss/models/store_income.dart';
import 'package:json_annotation/json_annotation.dart';
import 'dart:math';

part 'account_for_time.g.dart';

@JsonSerializable()
class StoreIncomeForTime extends Object {
  //营收时间段类型 1今日2本周3本月4本年
  int type;

  StoreIncome storeIncomeVO;

  //目标营业额
  @JsonKey(defaultValue: 0)
  int targetAmount;

  //完成进度
  double get progress {
    if (targetAmount == 0 || storeIncomeVO.totalAmount == 0) {
      return 0;
    }

    return min(1.0, storeIncomeVO.totalAmount / targetAmount);
  }

  String get title {
    Map<int, String> titles = {
      1: '今日数据统计',
      2: '本周数据统计',
      3: '本月数据统计',
      4: '今年数据统计',
    };

    return titles[type] ?? '--';
  }

  String get dateUnit {
    Map<int, String> titles = {
      1: '今日',
      2: '本周',
      3: '本月',
      4: '今年',
    };

    return titles[type] ?? '--';
  }

  StoreIncomeForTime(this.type, this.storeIncomeVO, this.targetAmount);

  factory StoreIncomeForTime.fromJson(Map<String, dynamic> srcJson) => _$StoreIncomeForTimeFromJson(srcJson);

  Map<String, dynamic> toJson() => _$StoreIncomeForTimeToJson(this);
}
